<style>
.pure_form_extra label, .pure_form_extra input { font-size: 12px !important; font-family: Trebuchet MS; }
.pure_form_extra .mandatory { color: #ff0000; padding-left: 5px; }
.pure_form_extra { background: #fff; padding: 10px; border: 1px solid #aaa; border-radius: 8px; font-size: 12px !important; }
</style>

<?php
$key = Utils::get_param('key', NULL);
if ($key) {
  $opts = new stdClass();
  $opts->cd = 't.reset_key = :v1';
  $opts->cdv = array(':v1' => $key);
  $rslt = $orm->get('pb_ecom_customer', NULL, NULL, NULL, NULL, $opts)->d;
}
?>

<?php if (!$key) { ?>
<div class="pure-form pure-form-aligned pure_form_extra">非法链接</div>
<?php } else if (!isset($rslt) || !isset($rslt[0])) { ?>
<div class="pure-form pure-form-aligned pure_form_extra">找不到用户</div>
<?php } else if ((time() - strtotime($rslt[0]->reset_exp)) > 1800) { ?>
<div class="pure-form pure-form-aligned pure_form_extra">超时，请重新发送邮件</div>
<?php } else { ?>
<div id="reset" class="pure-form pure-form-aligned pure_form_extra" style="width: 450px;">
  <legend>重置密码</legend>
  
  <div class="pure-control-group">
    <label>密码<span class="mandatory">*</span></label>
    <input onkeyup="__reset(event);" id="reset_pass" type="password" class="pure-input-1-2" placeholder="{password}" />
  </div>
  
  <div class="pure-control-group">
    <label>重输密码<span class="mandatory">*</span></label>
    <input onkeyup="__reset(event);" id="reset_retype" type="password" class="pure-input-1-2" placeholder="{password}" />
  </div>
  
  <div class="pure-control-group">
    <label>&nbsp;</label>
    <button class="pure-button pure-input-1-2 pure-button-primary" onclick="reset();">提交</button>
  </div>
</div>

<script type="text/javascript">
  var __requrl = '<?php echo Utils::get_requrl($app_data); ?>';
  var __key = '<?php echo $key; ?>';

  function __reset(ev) {
    if(ev.which == 13) {
      reset();
    }
  };
  
  function reset() {
    var req = {
      pass: $('#reset_pass').val(),
      retype: $('#reset_retype').val(),
      __key: __key
    };
    Ajax.request(
      __requrl + 'reset',
      'req=' + Utils.encodeURI(JSON.stringify(req)),
      function(rslt) {
        $('#reset').empty();
        $('#reset').append('密码已经重置');
        if (parent != window) {
          parent.____toolbar();
        } else {
          ____toolbar();
        }
      },
      null
    );
  };
</script>
<?php } ?>